# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/2 17:33
# @Author   : 郑鲁明
# @Site     : http://www.hzdledu.cn/
# @File     : prac.py
# @Software : PyCharm

# 在百度地图，练习ActionChains

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains

def foo1():
    driver = webdriver.Chrome()
    wait = WebDriverWait(driver, 30)
    driver.maximize_window()
    driver.get('https://map.baidu.com/@13376075,3522024,13z')

    # wait.until(expected_conditions.presence_of_element_located(()))
    wait.until(expected_conditions.presence_of_element_located((By.ID, 'sole-input')))
    driver.find_element(By.ID, 'sole-input').send_keys('胜利河美食街')

    wait.until(expected_conditions.presence_of_element_located((By.ID, 'search-button')))
    driver.find_element(By.ID, 'search-button').click()

    time.sleep(3)
    wait.until(
        expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="card-1"]/div/ul/li[1]/div[1]/div[1]/a')))
    driver.find_element(By.XPATH, '//*[@id="card-1"]/div/ul/li[1]/div[1]/div[1]/a').click()

    wait.until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="route-go"]/span[2]')))
    driver.find_element(By.XPATH, '//*[@id="route-go"]/span[2]').click()

    wait.until(expected_conditions.presence_of_element_located(
        (By.XPATH, '//*[@id="route-searchbox-content"]/div[2]/div/div[2]/div[1]/input')))
    driver.find_element(By.XPATH, '//*[@id="route-searchbox-content"]/div[2]/div/div[2]/div[1]/input').send_keys('贾家弄新村')

    driver.find_element(By.ID, 'search-button').click()

    # 选择步行
    time.sleep(2)
    driver.find_element(By.XPATH, '//*[@id="route-searchbox-content"]/div[1]/div[1]/div[3]').click()


    # 拖拽起点
    # wait.until(expected_conditions.presence_of_element_located((By.XPATH,'//*[@id="platform"]/div[2]/div[2]/div[2]')))
    # time.sleep(3)
    # ActionChains(driver).drag_and_drop_by_offset(driver.find_element(By.XPATH, '//*[@id="platform"]/div[2]/div[2]/div[2]'), 100, 100).perform()
    wait.until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="platform"]/div[2]/div[2]/div[2]')))
    time.sleep(2)
    ActionChains(driver).drag_and_drop_by_offset(
        driver.find_element(By.XPATH,'//*[@id="platform"]/div[2]/div[2]/div[2]'),100,100).perform()

    time.sleep(10)
    driver.quit()


if __name__ == '__main__':
    foo1()
